 <%   
 /** 
 * Description : select on of Ten welcome massages randomly using DBMS
 * update : logging error message when Database is unavailable using log4j
 * Date : 2/22/2014, update date : 2/28/2014
 * Written by : Kapsoo kim(nagoorum@naver.com) 
 */ 
 %>


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.DefectTracking.*" %>
<%@ page import="java.util.*, java.text.*" %>



<%

	/////////////////////////////////////
	// submit Database function /////
	/////////////////////////////////////

	
	//Receive data from submit_defect.jsp page(summary, defect_details)
	String summary = request.getParameter("defect_summary");
	String defect_details = request.getParameter("defect_detail").replaceAll("\"", "'");
	
	//Receive current_user_id from session
	int current_user_userid = 3; //session.getAttribute(userid); ///usering session.userid
		
	
	
	//Determine Today_date
	java.util.Date to_date = new java.util.Date(); 
	SimpleDateFormat sd_f = new SimpleDateFormat("yyyy-MM-dd");
	String submit_date = sd_f.format(to_date).toString();
	
	//Initial StatusID is 1(NEW) and ProjectID is 1
	String sql_defect_insert = "insert into defect(Summary, Details, DetectedBy, DetectedOn, StatusID, ProjectID)" +
								"values('" + summary + "','" + defect_details + "'," + current_user_userid + ",'" + submit_date + "', 1, 1 )";
	int insert_result = 0 ; 
	
	//TEMP--just verify the value of the webpage
	out.println("<br><br>summary=" + summary );
	out.println("<br><br>defect_details=" + defect_details );
	out.println("<br><br>current_user_id=" + current_user_userid );
	
	 
	
	//Declear DefectDetailManger 
	DefectDetailManager dmgr = new DefectDetailManager();
	
	insert_result = dmgr.setDefectInsert(sql_defect_insert);
	
	//TEMP-just verify the process
	out.println("<br><br>sql=" + sql_defect_insert );
	if (insert_result > 0) {
			out.println("<br>Successfuly updated<br><br>");
	}else{
			out.println("<br>Failed update<br><br>");
	}
	
	
	
	/////////////////////////////////////
	// Mail sending function /////
	/////////////////////////////////////
	
	String email_add = null;
	
	//Declear DefectDetailManger 
	DefectDetailManager smgr = new DefectDetailManager();	
	email_add = smgr.getUserEmailAdd(current_user_userid);
	
	//TEMP-mail address to test
	email_add = "nagoorum@naver.com";
	
	//Declear SendMail
	SendMail sendmail = new SendMail();
	sendmail.SendMainToAssignee(email_add, summary, defect_details);
	
 	
	//to list.jsp pages
	response.sendRedirect("./list.jsp");
	
%>
<br>